package com.example.hello;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

    public static final String EXTRA_MESSAGE = "com.example.hello.SaveMessage";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    public void saveMessage(View view){
        Intent intent = new Intent(this, ShowMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.edit_message);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        super.startActivity(intent);
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle presses on the action bar items
        switch (item.getItemId()) {
            case R.id.action_settings:
                return true;
            case R.id.action_clear:
                EditText editText = (EditText) findViewById(R.id.edit_message);
                editText.getEditableText().clear();                
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
    @Override 
    protected void onStop(){
        EditText edit = (EditText) findViewById(R.id.edit_message);
        edit.getEditableText().clear();

        super.onStop();
    }

}
